<?php

namespace App\Http\Middleware;

use App\Exceptions\Api\ApiUserNotLoginErrorException;
use App\Http\Requests\Api\ApiRequest;

use App\Models\User;
use Closure;

class ApiUser
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $apiRequest = new ApiRequest($request);

        if ($apiRequest->apiUser->get() instanceof User ){

            return $next($request);

        }else{
            throw  new ApiUserNotLoginErrorException('请登录');
        }


    }
}
